<template>
	<view class="content">
		<!-- 1 -->
		<view class="applyForm">
			<view class="formItem">
				<view class="label">
					姓名
				</view>
				<view class="value">
					<u--input placeholder="请输入姓名" v-model="form.name" border="none" clearable></u--input>
				</view>
			</view>
			<view class="formItem">
				<view class="label">
					手机
				</view>
				<view class="value">
					<u--input placeholder="请输入手机" v-model="form.phone" border="none" @blur="onInput"
						clearable></u--input>
				</view>
			</view>
		</view>
		<view class="submit" @click="onSubmit">
			提交
		</view>
	</view>
</template>

<script>
	import {
		applyPartner
	} from "@/api/partner.js";
	import {
		mapState
	} from "vuex"
	export default {
		data() {
			return {
				form: {
					name: '',
					phone: ''
				}

			};
		},
		computed: {
			...mapState("userInfo", ["Info", 'storeId']),
		},
		mounted() {

		},
		methods: {
			//校验手机号
			onInput(event) {
				const phoneRegex =
					/^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1589]))\d{8}$/; // 中国大陆手机号正则表达式
				const phoneNumber = event;
				if (phoneRegex.test(phoneNumber)) {
					this.form.phone = event;
				} else {
					this.form.phone = ''
				}
			},
			onSubmit() {
				console.log(this.Info, 'Info')
				// return
				let params = {
					// mobile: "17674577002",
					customerId: this.Info.id,
					phone: this.form.phone,
					realName: this.form.name
				};
				applyPartner(params).then((res) => {
					console.log(res);
					if (res.success) {
						console.log(res);


						uni.showToast({
							title: '申请成功',
							icon: 'success',
							duration: 2000, //提示的延迟时间，单位毫秒，默认：1500
							mask: true, // 是否显示透明蒙层， 防止触摸穿透， 默认： false
							// image:'./image.png',//自定义图标的本地路径
						});

						setTimeout(() => {
							uni.reLaunch({
								url: "/pages/applySuccess/applySuccess"
							})
						}, 1500)
					} else {
						// this.$mesaage.error(res.result.message);
						// uni.showToast({
						// 	title: '申请失败，请正确填写姓名和手机',
						// 	icon: 'error',
						// 	duration: 2000, //提示的延迟时间，单位毫秒，默认：1500
						// 	mask: true, // 是否显示透明蒙层， 防止触摸穿透， 默认： false
						// 	// image:'./image.png',//自定义图标的本地路径
						// });
					}
				});
			},
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;

		.applyForm {
			padding: 30rpx;
			width: 100%;

			.formItem {
				padding: 25rpx 0;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1px dotted #EBEBEB;

				.label {
					width: 30%;
				}

				.value {
					width: 70%;
				}
			}
		}

		.submit {
			position: fixed;
			width: 90%;
			margin: auto;
			bottom: 60rpx;
			left: 0;
			right: 0;
			text-align: center;
			padding: 20rpx 0;
			font-size: 26rpx;
			color: #fff;
			border-radius: 10rpx;
			background-image: linear-gradient(to right, #FF2828, #FD702B);
		}
	}
</style>